import java.util.ArrayList;

import javax.swing.event.TableModelEvent;
import javax.swing.table.AbstractTableModel;


public class TableModel extends AbstractTableModel {

	ArrayList<TableObject> tableData = new ArrayList<TableObject>();
	public TableModel(ArrayList<TableObject> td ) {
		tableData = td;
	}
	
	@Override
	public String getColumnName(int column) {
		String temp = "";
		switch(column)
		{
			case 0: temp = "Name"; break;
			case 1: temp = "Surname"; break;
			case 2: temp = "Age"; break;
		}
		return temp;
	}
	
	public void setTableObject(String n, String sn, int a)
	{
		tableData.add(new TableObject(n, sn, a));
	}
	@Override
	public int getColumnCount() {
		return 3;
	}

	@Override
	public int getRowCount() {
		return tableData.size();
	}

	@Override
	public Object getValueAt(int rowNum, int colNum) {
		switch(colNum)
		{
			case 0: return tableData.get(rowNum).getName();
			case 1: return tableData.get(rowNum).getSurname();
			case 2: return tableData.get(rowNum).getAge();
			default: return "";
		}
	}
	
	public void refrashView()
	{
		fireTableChanged(new TableModelEvent(this));
	}
}
